package com.edie.customview.modular.mymvpusebase;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.edie.customview.R;
import com.edie.customview.basemvp.BaseMvpActivity;
import com.edie.customview.modular.mymvp.MvpActivity;

/**
 * edie create on 2018/7/19
 */
public class MyMvpDemoActivity extends BaseMvpActivity< MyMvpDemoContract.IDemoPresenter>
        implements MyMvpDemoContract.IDemoView, View.OnClickListener {
    private TextView textView2;
    private EditText editText;

    public static void start(Context context) {
        context.startActivity(new Intent(context, MyMvpDemoActivity.class));
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_mvp_demo);
        initView();
    }

    @Override
    protected MyMvpDemoContract.IDemoPresenter initPresenter() {
        return new MyMvpDemoPresenterImpl(this);
    }

    private void initView() {
        findViewById(R.id.button2).setOnClickListener(this);
        findViewById(R.id.button3).setOnClickListener(this);
        textView2 = (TextView) findViewById(R.id.textView2);
        editText = (EditText) findViewById(R.id.editText);
    }

    @Override
    public void showMsg(String msg) {
        textView2.setText(msg);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.button2:
                String editTextString = editText.getText().toString().trim();
                if (TextUtils.isEmpty(editTextString)) {
                    Toast.makeText(this, "editTextString不能为空", Toast.LENGTH_SHORT).show();
                    return;
                }
                mPresenter.loadMsg(editTextString);
                break;
            case R.id.button3:
                MvpActivity.start(this);
                break;
        }
    }

}
